package com.itheima.health.dao;

import com.itheima.health.pojo.Setmeal;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * @Author: liangWeiQUQ
 * @Description:
 * @DateTime: 2021/2/27 17:16
 *
 **/
public interface SetmealDao extends Mapper<Setmeal> {
    /**
       * @Author: 传闻中的梁大侠 
       * @Date: 11:33 2021/3/9
       * @Parms []
       * @ReturnType: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
       * @Description: 查询套餐的详细信息
     */
    @Select("SELECT COUNT(t1.id) as value, t2.name FROM t_order t1 JOIN t_setmeal t2 ON t1.setmeal_id = t2.id GROUP BY t1.setmeal_id")
    List<Map<String, Object>> getCountSetmeal();
        /**
           * @Author: 传闻中的梁大侠
           * @Date: 12:26 2021/3/9
           * @Parms []
           * @ReturnType: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
           * @Description: 查询热门套餐统计
         */
    @Select("SELECT COUNT(t1.id) as setmeal_count, t2.name, COUNT(t1.id)/(SELECT count(id) FROM t_order) as proportion " +
            "FROM t_order t1 JOIN t_setmeal t2 ON t1.setmeal_id = t2.id GROUP BY t1.setmeal_id " +
            "ORDER BY setmeal_count DESC LIMIT 2")
    List<Map<String, Object>> findHotSetmeal();
}
